#!/usr/bin/python
# encoding: utf-8

import actions, graphics, _actions

class FileList:
  def __init__ (self, path):
    self.path = path
    self.command = ''
    self.files = []

class Skin:
  def __init__ (self, bgColor, selectedColor, itemHeights, fonts):
    self.bgColor = bgColor
    self.selectedColor = selectedColor
    self.itemHeights = itemHeights
    self.fonts = fonts

  def showFile (self, lish, idx):
    return []

  @staticmethod
  def textlet (level, left, width, font, text):
    return (level, left, width, font, unicode(text))

class Lish(actions.Actions):
  def __init__ (self, mainform, path, skin):
    actions.Actions.__init__(self, mainform)
    self.filelist = FileList(path)
    self.skin = skin

  def updateFileList (self):
    flist = self.filelist
    _actions.newFileList(self._mainform, unicode(flist.path), unicode(flist.command), len(flist.files))
    for i in xrange(0,len(flist.files)):
      ts = self.skin.showFile(self, i)
      _actions.addFile(self._mainform, unicode(flist.files[i]), len(ts))
      for t in ts:
        _actions.addFileTextlet(self._mainform, t[0], t[1], t[2], t[3], t[4])
    _actions.commitFileList(self._mainform)

  def updateSkin (self):
    skin = self.skin
    _actions.newSkin(self._mainform, skin.bgColor, skin.selectedColor,
                     len(skin.itemHeights), len(skin.fonts))
    for h in skin.itemHeights:
      _actions.addItemHeight(self._mainform, h)
    for f in skin.fonts:
      _actions.addFont(self._mainform, unicode(f.name), f.size, u' '.join(f.style),
                       unicode(f.pitch), f.color, f.charset)
    _actions.commitSkin(self._mainform)
    self.updateFileList()

